package mango.orm.oracle;

import mango.functions.FuncString;
import mango.orm.Dao;
import mango.orm.OrmException;
import mango.orm.impl.AbstractSQLMaker;

public class OracleSQLMaker extends AbstractSQLMaker {

    public String getLimitSql(String sql, int start, int limit) {
        int end = start + limit;
        StringBuilder limitString = new StringBuilder();
        limitString.append("select * from (select row_.*, rownum rownum_ from (");
        limitString.append(sql);
        limitString.append(") row_ where rownum <= ");
        limitString.append(end);
        limitString.append(") where rownum_ > ");
        limitString.append(start);
        return limitString.toString();
    }
    
    public int getDaoTypeBySql(String sql) {
        if (FuncString.isBlank(sql)) {
            throw new OrmException("an sql can't be null!");
        }
        String temp = sql.toUpperCase().trim();
        if (temp.startsWith("WITH")) {
            return Dao.TYPE_QUERY;
        }
        return super.getDaoTypeBySql(sql);
    }
}
